home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 26 / Cream of the Crop 26.iso / program / ddj0897.zip / RCSC.ZIP / LIB51 / ITOD.C < prev    next >
Text File  |  1997-01-12  |  628b  |  25 lines

  1. /*
  2. ** itod -- convert nbr to signed decimal string of width sz
  3. **         right adjusted, blank filled; returns str
  4. **
  5. **        if sz > 0 terminate with null byte
  6. **        if sz = 0 find end of string
  7. **        if sz < 0 use last byte for data
  8. */
  9. itod(nbr, str, sz)  int nbr;  char str[];  int sz;  {
  10.   char sgn;
  11.   if(nbr<0) {nbr = -nbr; sgn='-';}
  12.   else sgn=' ';
  13.   if(sz>0) str[--sz]=NULL;
  14.   else if(sz<0) sz = -sz;
  15.   else while(str[sz]!=NULL) ++sz;
  16.   while(sz) {
  17.     str[--sz]=(nbr%10+'0');
  18.     if((nbr=nbr/10)==0) break;
  19.     }
  20.   if(sz) str[--sz]=sgn;
  21.   while(sz>0) str[--sz]=' ';
  22.   return str;
  23.   }
  24.  
  25.